package com.gong.ioc;

import com.gong.ioc.service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;


@ComponentScan(basePackages = "com.gong")
@SpringBootApplication
public class IocApplication {

    public static void main(String[] args) {

        ApplicationContext context = SpringApplication.run(IocApplication.class, args);
        //通过类型获取Bean
        HelloController bean = context.getBean(HelloController.class);
        bean.sayHello();

        //通过名称获取Bean
        HelloController helloController = (HelloController) context.getBean("helloController");
        helloController.sayHello();

        //通过类型加名称获取
        HelloController helloController1 = context.getBean("helloController", HelloController.class);
        helloController1.sayHello();
    }
    //三者获取的是同一个对象
    //默认是单例模式*/

    }

